﻿<%@ Page Title="Delovni nalogi" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="els_web._Default"   %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <script type="text/javascript" language="javascript">
        function redirect(cumtomerName) {
            var gvObject = document.getElementById(cumtomerName);
            if (gvObject.style.display == "none") {
                gvObject.style.display = "inline";
            }
            else {
                gvObject.style.display = "none";
            }
            return false;
        }

</script>
    <p>
    <script  type="text/javascript" language="javascript">
        function Highlight(cumtomerName) {
            var gvObject = document.getElementById(cumtomerName);
            try
            {
                gvObject.style.color = 'Red';
            }
            catch(Err)
            { }

        }
        function UnHighlight(cumtomerName) {
            var gvObject = document.getElementById(cumtomerName);
            try
            {
                gvObject.style.color = 'GrayText';
            }
            catch (Err)
            { }
        }
        
        function SelectAll(id)
        {
            //get reference of GridView control
            var grid = document.getElementById("<%= GridView1.ClientID %>");
            //variable to contain the cell of the grid
            var cell;
            
            if (grid.rows.length > 0)
            {
                //loop starts from 1. rows[0] points to the header.
                for (i=1; i<grid.rows.length; i++)
                {
                    //get the reference of first column
                    cell = grid.rows[i].cells[4];
                    
                    //loop according to the number of childNodes in the cell
                    for (j=0; j<cell.childNodes.length; j++)
                    {           
                        //if childNode type is CheckBox                 
                        if (cell.childNodes[j].type =="checkbox")
                        {
                        //assign the status of the Select All checkbox to the cell checkbox within the grid
                            cell.childNodes[j].checked = document.getElementById(id).checked;
                        }
                    }
                }
            }
        }



    </script>

 
                           
    Delovni nalog<asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="SqlDataSource1" DataTextField="NALOG" DataValueField="NALOG" 
        Height="21px" Width="170px" AutoPostBack="True" AppendDataBoundItems="true" 
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Text="--Select One--" Value="" />           
    </asp:DropDownList>
        <script runat="server">
           private bool avtenticiran1()
           {
               if (User.Identity.IsAuthenticated)
                   return true;
               else
                   return false;
           }
           private bool avtenticiran()
           {
               if (User.Identity.IsAuthenticated)
                   return true;
               else
                   return false;
           }
        </script>  
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <asp:GridView ID="GridView1" runat="server" AllowSorting="True"
            AutoGenerateColumns="False" DataSourceID="SqlDataSource2" OnRowDataBound="RowDataBound" >
            <Columns>
                <asp:BoundField DataField="PROCESNA" HeaderText="PROCESNA" 
                    SortExpression="PROCESNA" />
                <asp:BoundField DataField="SERIJSKA" HeaderText="SERIJSKA" 
                    SortExpression="SERIJSKA" />              
                <asp:TemplateField HeaderText="OPERACIJE">
                  <ItemTemplate>
                    <div id="<%#Eval("PROCESNA")%>" style="display:none; position:relative;"  >
                        <asp:Label ID="lblUserName" runat="server" Text='<%# Eval("PROCESNA") %>' Visible="false" />
                        <asp:SqlDataSource ID="SqlDataSource_det" runat="server" DataSourceMode="DataSet" 
                            ConnectionString="DRIVER=SQL Server;SERVER=vmie3;UID=uporabnik;PWD=uporabnik;APP=Microsoft® Visual Studio® 2010;WSID=PURKATLAP;DATABASE=KAKOVOST" 
                            ProviderName="<%$ ConnectionStrings:KAKOVOSTConnectionString.ProviderName %>" 
                            SelectCommand="SELECT * FROM [SPREMNILISTIZDELKA] WHERE ([PROCESNA] = ?)" >
                            <SelectParameters>
                                <asp:ControlParameter ControlID="lblUserName" Name="NALOG" PropertyName="Text" Type="String" />
                            </SelectParameters>
                        </asp:SqlDataSource>   
                        <asp:SqlDataSource ID="SqlDataSource6" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:KAKOVOSTConnectionString %>" 
                            ProviderName="<%$ ConnectionStrings:KAKOVOSTConnectionString.ProviderName %>" 
                            SelectCommand="SELECT [OPERACIJA], [OPERATER], [POZICIJA], [NAPAKA], [OPIS], [ID_IZDELEK] FROM [SPREMNILISTNAPAK] WHERE ([PROCESNA] = ?)">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="lblUserName" Name="NALOG" PropertyName="Text" Type="String" />
                            </SelectParameters>
                        </asp:SqlDataSource>   
                        <script runat="server">
                            private string getOperaterName(object id)
                            {
                                operaterji_ operatercek = operaterji.Find(delegate(operaterji_ p) { return p.ID == Convert.ToInt32(id); });
                                return operatercek.ime;
                            }
                            private string getStatus(object id)
                            {
                                statusi_ statusek = statusi.Find(delegate(statusi_ p) { return p.ID == Convert.ToInt32(id); });
                                return statusek.opis;
                            }
                            private string getNapaka(object id)
                            {
                                napake_ napakce = napake.Find(delegate(napake_ p) { return p.ID == Convert.ToInt32(id); });
                                return napakce.opis;
                            }
                            private string getNapakaEPC(object id)
                            {
                                napake_ napakce = napake.Find(delegate(napake_ p) { return p.ID == Convert.ToInt32(id); });
                                return napakce.koda;
                            }                       
                        </script>
                        <asp:GridView BorderColor="GrayText" ID="NASTY" runat="server" AutoGenerateColumns="False" DataKeyNames="OPERATER" DataSourceID="SqlDataSource_det"  >
                            <Columns>
                            
                                    <asp:BoundField DataField="PROCESNA" HeaderText="Procesna št."/>
                                    <asp:BoundField DataField="DATUM" HeaderText="Datum"/>
                                    <asp:BoundField DataField="OPERACIJA" HeaderText="Operacija"/>
                                    <asp:TemplateField HeaderText="Operater">
                                     <ItemTemplate>
                                         <div id='<%# Eval("ID") %>'>
                                              <asp:Label ID="lbloperater" runat="server"
                                                        Text='<%# Eval("OPERATER") %>' 
                                                        Tooltip='<%# getOperaterName(Eval("OPERATER")) %>'>
                                              </asp:Label>    
                                        </div>  
                                    </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Rezultat">
                                     <ItemTemplate>
                                          <asp:Label ID="lblstatus" runat="server"
                                                    Text= '<%# getStatus(Eval("REZULTAT")) %>'
                                                    Tooltip='<%# Eval("REZULTAT") %>'>
                                          </asp:Label>      
                                     </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="TEST" HeaderText="Komentar testa"/>
                            </Columns>
                        </asp:GridView>
                    </div> 
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="NAPAKE">
                    <ItemTemplate>
                            <% if ((bool)Application["aoi_napake"]) { %>
                            <asp:GridView  ID="aoiGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="Topology" DataSourceID="SqlDataSource10" >                           
                                <Columns>
                                    <asp:BoundField DataField="Topology" HeaderText="Element"/>
                                    <asp:BoundField DataField="Repair_error_comment" HeaderText="Napaka"/>
                                </Columns>
                            </asp:GridView>
                            <% }  %>
                        <asp:GridView  ID="napakeGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="POZICIJA" DataSourceID="SqlDataSource6" OnRowDataBound="RowDataBound1" >
                            <Columns>
                                    <asp:TemplateField HeaderText="Operacija" >
                                        <ItemTemplate>
                                              <asp:Label ID='operacija' runat="server"
                                                        Text='<%# Eval("OPERACIJA") %>' 
                                                        Tooltip='<%# Eval("ID_IZDELEK") %>'>
                                              </asp:Label>      
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Operater">
                                        <ItemTemplate>
                                              <asp:Label ID='operater' runat="server"   
                                                        Text='<%# Eval("OPERATER") %>' 
                                                        Tooltip='<%# getOperaterName(Eval("OPERATER")) %>'>
                                              </asp:Label>      
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="POZICIJA" HeaderText="Pozicija"/> 
                                    <asp:TemplateField HeaderText="Napaka">
                                     <ItemTemplate>
                                          <asp:Label ID="napaka" runat="server"
                                                    Text='<%# getNapakaEPC(Eval("NAPAKA")) %>' 
                                                    Tooltip='<%# getNapaka(Eval("NAPAKA")) %>'>
                                          </asp:Label>      
                                     </ItemTemplate>
                                    </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField >
                    <AlternatingItemTemplate>
                        <asp:CheckBox ID="cbSelectAll" runat="server" Enabled='<%# avtenticiran() %>' />
                    </AlternatingItemTemplate>
                    <HeaderTemplate>
                        <asp:CheckBox ID="cbSelectAll" runat="server" Text="IZHOD" Enabled='<%# avtenticiran() %>' />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="cbSelectAll" runat="server" Enabled='<%# avtenticiran() %>' />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <% if (avtenticiran()) { %>
            <asp:Button ID="Button1" runat="server" Text='Potrdi' onclick="Button1_Click" />
        <% } %>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="DRIVER=SQL Server;SERVER=vmie3;UID=uporabnik;PWD=uporabnik;APP=Microsoft® Visual Studio® 2010;WSID=PURKATLAP;DATABASE=KAKOVOST" 
        ProviderName="<%$ ConnectionStrings:KAKOVOSTConnectionString.ProviderName %>" 
        SelectCommand="SELECT DISTINCT [NALOG] FROM [SPREMNILISTIZDELKA]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="DRIVER=SQL Server;SERVER=vmie3;UID=uporabnik;PWD=uporabnik;APP=Microsoft® Visual Studio® 2010;WSID=PURKATLAP;DATABASE=KAKOVOST" 
        ProviderName="<%$ ConnectionStrings:KAKOVOSTConnectionString.ProviderName %>" 
        SelectCommand="SELECT DISTINCT PROCESNA, SERIJSKA FROM [SPREMNILISTIZDELKA] WHERE ([NALOG] = ?)">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="NALOG" 
                PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
        ConnectionString="DRIVER=SQL Server;SERVER=vmie3;UID=uporabnik;PWD=uporabnik;APP=Microsoft® Visual Studio® 2010;WSID=PURKATLAP;DATABASE=KAKOVOST" 
        ProviderName="<%$ ConnectionStrings:KAKOVOSTConnectionString.ProviderName %>" 
        SelectCommand="SELECT * FROM [SPREMNILISTIZDELKA]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
        ConnectionString="<%$ ConnectionStrings:KAKOVOSTConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:KAKOVOSTConnectionString.ProviderName %>" 
        SelectCommand="SELECT [KODA] FROM [SEZKOD] WHERE ([ID] = (SELECT [KODA] FROM [DELNALOGI] WHERE [DELNALOG] = ?))">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="NALOG" 
                PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource5" runat="server" DataSourceMode="DataSet" 
        ConnectionString="<%$ ConnectionStrings:KAKOVOSTConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:KAKOVOSTConnectionString.ProviderName %>" 
        SelectCommand="SELECT [ID], [KONTROLOR], [IME] FROM [SEZKONTROLORJEV]">
    </asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource7" runat="server" 
        ConnectionString="<%$ ConnectionStrings:KAKOVOSTConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:KAKOVOSTConnectionString.ProviderName %>" 
        SelectCommand="SELECT * FROM [SPREMNILISTREZULTAT]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource8" runat="server" 
        ConnectionString="<%$ ConnectionStrings:KAKOVOSTConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:KAKOVOSTConnectionString.ProviderName %>" 
        SelectCommand="SELECT [ID], [NAPAKA], [KODANAPAKE] FROM [SEZNAPAK]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource10" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AOI20070906ConnectionString %>" 
            ProviderName="<%$ ConnectionStrings:AOI20070906ConnectionString.ProviderName %>" 
            SelectCommand="SELECT Topology, Repair_Error_Comment FROM TESTED_OBJECT WHERE Card_Id in (SELECT Card_Id FROM CARDS WHERE Card_Bar_Code LIKE ? + '%')">
        <SelectParameters>
            <asp:Parameter Name="Card_Bar_Code" Type="String" />
        </SelectParameters>
        </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource9" runat="server"
        ConnectionString="<%$ ConnectionStrings:KAKOVOSTConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:KAKOVOSTConnectionString.ProviderName %>" 
        SelectCommand="SELECT * FROM [SPREMNILISTIZDELKA] WHERE (PROCESNA = ?)"
        UpdateCommand="IF NOT EXISTS (SELECT * FROM [SPREMNILISTIZDELKA] WHERE PROCESNA = @PROCESNA AND REZULTAT = 1) INSERT INTO [SPREMNILISTIZDELKA] (PROCESNA, SERIJSKA, NALOG, DATUM, OPERATER, REZULTAT) VALUES (@PROCESNA, @SERIJSKA, @NALOG, GetDate(), 0, 1);" 
        DeleteCommand="DELETE FROM [SPREMNILISTIZDELKA] WHERE PROCESNA=? AND REZULTAT=1;" >
        <DeleteParameters>
            <asp:Parameter Name="PROCESNA" Type="String" />            
        </DeleteParameters>
        <SelectParameters>
            <asp:Parameter Name="PROCESNA" Type="String" />
        </SelectParameters>

    </asp:SqlDataSource>
</p>
</asp:Content>